{{ template "header" . }}
{{ template "golfer" . }}

<main>
    <div id=wall>
{{ $lastDate := "" }}
{{ range .Data.Wall }}
    {{ if ne .Date $lastDate }}
        <time>{{ .Date }}</time>
        {{ $lastDate = .Date }}
    {{ end }}
        {{ $golfer := .Golfer }}
        <img loading=lazy src="{{ avatar .AvatarURL 48 }}">

    {{ if gt (len .Cheevos ) 1 }}
        <details>
            <summary>
                <a href="/golfers/{{ $golfer }}">{{ $golfer }}</a>
                earned {{ len .Cheevos }} achievements:
                {{ range.Cheevos }}
                    <span title="{{ .Name }}: {{.Description }}">{{ .Emoji }}</span>
                {{ end }}
            </summary>
        {{ range .Cheevos }}
            <div>
                <a href="/golfers/{{ $golfer }}">{{ $golfer }}</a>
                earned {{ .Emoji }}
                <a href="/rankings/cheevos/{{ .ID }}">{{ .Name }}</a>
            </div>
        {{ end }}
        </details>
    {{ else }}
        <div>
            <a href="/golfers/{{ .Golfer }}">{{ .Golfer }}</a>

        {{ if .Cheevos }}{{ with index .Cheevos 0 }}
            earned {{ .Emoji }}
            <a href="/rankings/cheevos/{{ .ID }}">{{ .Name }}</a>
        {{ end }}{{ else if .Hole }}
            solved <a href="/{{ .Hole.ID }}#{{ .Lang.ID }}">
                {{ .Hole.Name }} in {{ .Lang.Name }}</a>
        {{ else }}
            followed <a href="/golfers/{{ $.GolferInfo.Name }}">
                {{ $.GolferInfo.Name }}</a>
        {{ end }}
        </div>
    {{ end }}
{{ end }}
    </div>

    <aside>
    {{ with .Data.Connections }}
        <section id=connections>
        {{ range . }}
            {{ $url := "" }}
            {{ if eq .Connection "discord" }}
                {{ $url = print "//discord.com/users/" .ID }}
            {{ else if or (eq .Connection "github") (eq .Connection "gitlab") }}
                {{ $url = print "//" .Connection ".com/" .Username }}
            {{ else if eq .Connection "gravatar" }}
                {{ $url = print "//gravatar.com/" .Username }}
            {{ else if eq .Connection "stack-overflow" }}
                {{ $url = print "//stackoverflow.com/users/" .ID }}
            {{ end }}

            <a {{ with $url }} href="{{ . }}" {{ end }}
                title="{{ (index $.Data.OAuthProviders .Connection).Name }}">
                {{ svg .Connection }}
                <div>
                    {{ .Username }}
                {{- with .Discriminator.V -}}
                    <span>{{ printf "#%04d" . }}</span>
                {{- end -}}
                </div>
            </a>
        {{ end }}
        </section>
    {{ end }}

    <section id=category-overview>
        <h2>Category Overview</h2>
        <canvas></canvas>
    </section>

    {{ with .Data.Langs }}
        <section class=icons>
            <h2>{{ len . }} / {{ $.GolferInfo.LangsTotal }} Languages</h2>
        {{ range . }}
            <a class="rank-{{ .RankMin }}"
                href="/rankings/holes/all/{{ .Lang.ID }}/bytes"
               title="{{ .Lang.Name }}: {{/* */}}
                {{- .RankBytes }}{{ ord .RankBytes }} in Bytes
                {{- with .RankChars }}, {{ . }}{{ ord . }} in Chars{{ end }}.">
                {{ svg .Lang.ID }}
            </a>
        {{ end }}
        </section>
    {{ end }}

        <section id=cheevos class=icons>
            <h2>
                {{ len .GolferInfo.Cheevos }} / {{ .GolferInfo.CheevosTotal }}
                Achievements
            </h2>
    {{ range $category, $cheevos := .Cheevos }}
        {{ range $cheevos }}
            <a {{ if $.GolferInfo.Earned .ID }} class="earned" {{ end }}
                href="/rankings/cheevos/{{ .ID }}"
                title="{{ .Name }} - {{ .Description }}">{{ .Emoji }}</a>
        {{ end }}
    {{ end }}
        </section>

    {{ if gt (len .Data.Following) 1 }}
        {{ $name := "" }}
        {{ with .Golfer }}{{ $name = .Name }}{{ end }}
        <table class=nowrap-second>
            <thead>
                <tr>
                    <th colspan=2>
                    {{ with dec (len .Data.Following) }}
                        {{ . }} Following
                    {{ end }}
                    <th class=right>Bytes
                    <th class=right>Chars
            <tbody>
            {{ range .Data.Following }}
                <tr {{ if eq $name .Name }} class=me {{ end }}>
                    <td>{{ .Rank }}<sup>{{ ord .Rank }}</sup>
                    <td>{{ template "golfer-link" . }}
                    <td class=right>{{ comma .Bytes }}
                    <td class=right>{{ comma .Chars }}
            {{ end }}
        </table>
    {{ end }}

    {{ with .Data.Followers }}
        <section class=icons>
            <h2>{{ amount (len .) "Follower" }}</h2>
        {{ range . }}
            <a href="{{ .Name }}" title="{{ .Name }}">
                <img loading=lazy src="{{ avatar .AvatarURL 72 }}">
            </a>
        {{ end }}
        </section>
    {{ end }}
    </aside>
</main>

<script id=category-overview-data type=application/json>
    {{ .Data.CategoryOverview }}
</script>

{{ template "settings-dialog" . }}
{{ template "footer" }}
